#ifndef SINGLETON_THREAD_POOL_H
#define SINGLETON_THREAD_POOL_H

#include "Singleton.h"

#include <mutex>
#include <condition_variable>
#include <thread>
#include <vector>
#include <functional>
#include <queue>
#include <memory>

class ThreadPool : public Singleton<ThreadPool>{
    friend Singleton<ThreadPool>;
public: 
    ThreadPool(const ThreadPool&) = delete;
    ThreadPool& operator=(const ThreadPool&) = delete;

    using Task = std::function<void(void)>;

    void append(Task task);

    void stop();

    void run();
private:
    ThreadPool();

    std::mutex m_mutex;
    std::condition_variable m_cond;
    std::vector<std::unique_ptr<std::thread>> m_threads;
    bool m_stop = false;
    std::queue<Task> m_tasks;
};

#endif // SINGLETON_THREAD_POOL_H